package Bank;

import java.sql.ResultSet;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Employee {
	
	private String employee_name;
	private String employee_password;
	private int employee_id;
		
	public String getEmployee_name() {
		return employee_name;
	}
	public void setEmployee_name(String employee_name) {  
		this.employee_name = employee_name;
	}
	public String getEmployee_password() {
		return employee_password;
	}
	public void setEmployee_password(String employee_password) {
		this.employee_password = employee_password;
	}
	public int getEmployee_id() {
		return employee_id;
	}
	public void setEmployee_id(int employee_id) {
		this.employee_id = employee_id;
	}

	public void registerManager() {
		Scanner in = new Scanner(System.in);
		long id =0;
		boolean flag_id;
		String name;
		System.out.println("Please enter Employee's information");
	do{
	    flag_id = true;
		System.out.print("Employee_id:-");
	try{
		id = in.nextLong();
		in.nextLine();
		String query_e = "select * from employee_table where employee_id = "+id;
		int n_e = new ConnDB().uprs(query_e);
		String query_c = "select * from customer_table where customer_id = "+id;
		int n_c = new ConnDB().uprs(query_c);
		if(n_e!=0){
			System.out.println("The Employee ID is existed in employee! Please enter again~");
			flag_id = false;
		}
		if(n_c!=0){
			System.out.println("The Employee ID is used in customer! Please enter again~");
			flag_id = false;
		}
    }catch(InputMismatchException e){
 	   in.nextLine();
 	   System.out.println("The id only for digits!!");
       flag_id =false;
	    }
	}while(flag_id == false);
	
	//判断name是否为空，是否是数字或字母或下划线
	     boolean flag_name;
	  do{
		  flag_name = true;
		System.out.print("Employee_name(6-20 words):-");
		String name_z = "\\w{6,20}";
		name = in.nextLine();
		if(!name.matches(name_z)){
			System.out.println("The name must be digists or letters or underscores! Please enter again~");
			flag_name=false;
		}
	  }while(flag_name==false);
	  	  
	  //password 为6位数字
		boolean flag1=false;
		String password;
		do{
			System.out.print("Employee_password(It's only for six digits):-");
		    String password1 = "\\d{6}";
		    password = in.nextLine();
		    if(password.matches(password1)){		   
		        flag1 = true;			
		    }else{
			    System.out.println("The password is illegal!Please enter again~");
		       }
		  }while(flag1==false);		
		String Query="insert into EMPLOYEE_TABLE(EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_PASSWORD,EMPLOYEE_ROLE,EMPLOYEE_TYPE)values("+id+",'"+name+"','"+password+"','"+"manager','employee')";	
		int flag=new ConnDB().uprs(Query);
		if(flag==1){
			System.out.println("RegisterManager sucessfully!");
		
		}else{
			System.out.println("RegisterManager failed!");
		}
	
	}
	
	public void deleteManager(){
		System.out.println("please input manager name ");
		Scanner in = new Scanner(System.in);
		String username = in.nextLine();
		if(new ConnDB().usernameIsExist("employee_table", username) == 1){
			int i = new ConnDB().uprs("delete from employee_table where employee_name = '"+username + "'");
			if(i==1){
				System.out.println("delete successed");
			}else{
				System.out.println("delete failed");
			}
		}else{
			System.out.println("username is not exist");
		}
		
	}
	
	
}
